package org.rvk.vms.service.user;

import org.rvk.vms.api.user.IUserService;
import org.rvk.vms.dal.dao.GenericDao;
import org.rvk.vms.dal.entities.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;

public class UserDetailServiceImpl implements UserDetailsService {

	@Autowired
	private IUserService vmsUserService;
	
	@Autowired 
	private GenericDao genericDao;
	
	@Override
	public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
		System.out.println("#### Calling user service to load detail...");
	    User user =	vmsUserService.getUser(username);
	    System.out.println("#### Userdetail found...");
		if (user != null) {
			VmsUser vmsUser = new VmsUser();
			vmsUser.setUser(user);
			return vmsUser;
		}
	    throw new UsernameNotFoundException("no user found for user name ="+username);
	}

	/**
	 * @return the vmsUserService
	 */
	public IUserService getVmsUserService() {
		return vmsUserService;
	}

	/**
	 * @param vmsUserService the vmsUserService to set
	 */
	public void setVmsUserService(IUserService vmsUserService) {
		this.vmsUserService = vmsUserService;
	}

	/**
	 * @return the genericDao
	 */
	public GenericDao getGenericDao() {
		return genericDao;
	}

	/**
	 * @param genericDao the genericDao to set
	 */
	public void setGenericDao(GenericDao genericDao) {
		this.genericDao = genericDao;
	}
	
	

}
